Date: Mon, 11 Nov 1996 17:23:53 GMT
Server: NCSA/1.5
Content-type: text/html
Last-modified: Wed, 06 Nov 1996 04:29:43 GMT
Content-length: 4494

<HTML> <HEAD> <TITLE>CS110, Program 1</TITLE> </HEAD>

<body>

<H1> Program 1 -- Polygons on the March </H1>

<H3> Due Date: Wednesday, November 13 </H3>

<H2> Some Background </H2>

A <EM>polygon</EM> is a flat shape with 3 or more sides, all of which
are straight (e.g. a triangle is a 3-sided polygon).  When all the
sides of a polygon have the same length, the polygon is called
<em>regular</em>.  Equilateral triangles and squares are regular
polygons with 3 and 4 sides respectively. 

<P>All regular polygons can be fit perfectly within a circle (such that the
circle touches all the corners of the polygon).  This circle is called
the <em>circumscribed circle</em>. 

<H2> The Problem </H2>

<P>You are to write a program that will perform a few calculations on
regular polygons.  Your program will ask the user (1) how many sides
the polygon has, and (2) what the length of each side is.  Remember,
all sides have the same length so part (2) is just one question!  The
number of sides should be stored in an integer variable, and all other
variables should be of type <strong>double</strong>. 

<P>As output, your program will display (1) the area of the polygon,
and (2) the radius of the circumscribed circle.  Just use the formulas
given below; you don't need to understand them at all! 

<P>In addition to the requirements above, print a welcoming message when the
program starts and an exiting message when the program ends (see
sample printout; use any messages you like!). 

<P>Finally, put a comment at the beginning of your program briefly
describing the purpose of the program (use 1 or 2 sentences).  Of
course, put your name and login name in comments at the beginning of
the program just like in assignment 0. 

<H2> The Formulas </H2>

In the following equations, <em>sides</em> is the number of sides,
<em>edge</em> is the length of each side, <em>radius</em> is the
radius of the circumscribed circle, and <em>area</em> is the area of
the polygon.  Note that <em>sides</em> and <em>edge</em> are what the
user enters, and <em>radius</em> and <em>area</em> are what the
program outputs.  Also note that <em>edge</em> is squared in the formula for <em>area</em>.

<P><P>

<IMG ALIGN=MID SRC="prog1.equation.jpg" ALT="The formula is too complicated
to view in text form; you need to see the picture">

<H2> A Sample Run </H2>

<pre>
Step inside the amazing polygonator... 

Number of sides? 4
Length of each side? 7.82

Area of polygon: 61.1524
Radius of circumscribed circle: 5.529575

That's all, folks!
</pre>

<H2> Hints </H2>

<li> Don't write the whole program at once!  For example, start by
writing a program which only displays some messages.  When that is
working, create some variables and add the input commands.  Test your
input statements by redisplaying what the user has typed in.  Finally,
add the math commands to finish the program. 

<li> Use <strong>pow(x,y)</strong> for calculating the square root.
For example, pow(7, 0.5) calculates the square root of 7. 

<li> Remember to use <strong>#include&lt;math.h&gt;</strong>, since
you will need cos(), sin(), and pow().  Of course, you also need
<strong>#include&lt;iostream.h&gt;</strong> in order to use
<strong>cout</strong> and <strong>cin</strong>. 

<li> Use meaningful variable names.  Avoid one-letter names unless
they make your program more understandable. 

<li> Create some variables to store intermediate calculations. 

<li> Test your program on several cases for which you already know the correct
answers.  For instance, see the sample run given above for a square.
Here's another case: when the number of sides is 3 and the length of each side is
2.1, the area is 1.909586 and the radius is 1.2124356. 

<H2>What to turn in</H2>

Turn in the following two pages, <B>stapled together:</B>

<li> (page 1) <em>Printed listing of the source file.</em> This is to
be done just like in program 0. 

<li> (page 2) <em>Printed copy of your program's output when run on a
sample test case.</em>  This can be done easily as follows: After
running your program, pull down the little tab button on the upper
left hand corner of the output window (the window with INACTIVE at the
top), and select the Print option . This will send all output
generated by your program  in this window to the printer. 

<P> In addition, as with all assignments, <EM>you must electronically turn in a
copy of your program's source code</EM>.  Use the filename "<STRONG>program1.cpp</strong>".

</BODY> </HTML>








